﻿package com.neriksworkshop.lib.colourLovers.core 
{
	import com.neriksworkshop.lib.colourLovers.items.IItem
	import com.neriksworkshop.lib.colourLovers.params.Params;
	import flash.events.EventDispatcher;
	
	/**
	 * ...
	 * @author ...
	 */
	public class AbstractItem extends EventDispatcher implements IItem
	{
		
		//from colourlovers api
		protected var _id:int;
		protected var _userName:String;		
		protected var _url:String;
		protected var _apiUrl:String;
		
		public function AbstractItem(self:AbstractItem) 
		{
			if(self != this) throw Params.ERROR_ABSTRACT_CLASS;
		}
		

		public function buildFromData(data:*):void
		{
			_id = int(data.id);
			_userName = data.userName;
			_url = data.url;
			_apiUrl = data.apiUrl;
			
			//for (var name:String in data) trace(name, data[name]);
		}
		/*
		public function buildFromXML(xmlData:XML):void
		{

			
			for each (var xmlNode:* in xmlData.children()) 
			{
				if (xmlNode.hasSimpleContent())
				{
					_params[xmlNode.localName()] = xmlNode; 
				}
				else
				{
					_params[xmlNode.localName()] = buildArrayFromNode(xmlNode);
				}
			}
		}
		
		
		public function buildFromJSON(jsonData:Object):void
		{
			_id = int(jsonData.id);
			_userName = jsonData.userName;
			_url = jsonData.url;
			_apiUrl = jsonData.apiUrl;			
			
			for (var name:String in jsonData) trace(name, jsonData[name]);
		}*/
		
		
		public function get id():int { return _id; }
		
		public function get userName():String { return _userName; }
		
		public function get url():String { return _url; }
		
		public function get apiUrl():String { return _apiUrl; }
		
		
		/*
		private function buildArrayFromNode(xmlData:XML):Array
		{
			var a:Array = new Array();
			
			for each (var xmlNode:* in xmlData.children()) 
			{
				if (xmlNode.hasSimpleContent())
				{
					a.push(xmlNode)
				}
				else
				{
					a.push(buildArrayFromNode(xmlNode));
				}
			}
			
			return a;
		}*/
		

				
		
	}
	
}